﻿using FlyHorse.LIMS.IBLL;
using FlyHorse.LIMS.Model;
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Text;

namespace FlyHorse.LIMS.BLL
{
    public partial class ReportRawBll : BaseBll<ReportRaw>, IReportRawBll
    {
        public bool AddReportRaw(ReportRaw reportRaw)
        {
            DbContext db = this.CurrentDBSession.Db;
            db.Set<ReportRaw>().Add(reportRaw);
            int res = db.SaveChanges();
            if (res > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        public List<ReportRawResult> GetEmptReusltListByGoodsID(string goodsID)
        {
            List<ReportRawResult> reportRawResultList = new List<ReportRawResult>();

            //查询标准
            List<StandardRaw> standardList = this.CurrentDBSession.StandardRawDal.LoadEntities(m =>  m.GoodsID == goodsID).OrderBy(m=>m.FormOrder).ToList();
            foreach (var standard in standardList)
            {
                ReportRawResult reportRawResult = new ReportRawResult();
                reportRawResult.Basis = standard.TestItem.Basis;
                reportRawResult.ChineseName = standard.TestItem.ChineseName;
                reportRawResult.FormOrder = standard.FormOrder;
                reportRawResult.ReportRawResultID = Guid.NewGuid().ToString();
                reportRawResult.MaxValue = standard.MaxValue;
                reportRawResult.MinValue = standard.MinValue;
                reportRawResult.TestItemID = standard.TestItemID;
                reportRawResult.TestValue = null;
                reportRawResult.Unit = standard.TestItem.Unit;
                reportRawResultList.Add(reportRawResult);
            }
            return reportRawResultList;
        }

        public bool DeleteRawReportAndRestult(ReportRaw report)
        {
            using (OJCB4Entities db =new OJCB4Entities())
            {
                ReportRaw entity = db.ReportRaws.Find(report.ReportRawID);
                if (entity!=null)
                {
                    db.Set<ReportRaw>().Remove(entity);
                    int count = db.SaveChanges();
                    if (count > 0)
                    {
                        return true;
                    }
                    else
                    {
                        return false;
                    }
                }
                else
                {
                    return false;
                }
                
            }
            
        }

       

       
    }
}
